﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Cms.Core.Data.Migrations
{
    public partial class _20190510 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AlterColumn<string>(
                name: "Name",
                table: "SysRole",
                type: "nvarchar(50)",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nvarchar(10)",
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "Code",
                table: "SysRole",
                type: "nvarchar(50)",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nvarchar(10)",
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "Name",
                table: "SysPermission",
                type: "nvarchar(200)",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "nvarchar(10)",
                oldNullable: true);

            migrationBuilder.AlterColumn<bool>(
                name: "IsEnabled",
                table: "SysPermission",
                nullable: false,
                defaultValue: true,
                oldClrType: typeof(bool));

            migrationBuilder.AlterColumn<string>(
                name: "Icon",
                table: "SysPermission",
                type: "nvarchar(100)",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nchar(10)",
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "Code",
                table: "SysPermission",
                type: "nvarchar(50)",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nvarchar(10)",
                oldNullable: true);

            migrationBuilder.AddColumn<string>(
                name: "Action",
                table: "SysPermission",
                type: "varchar(50)",
                nullable: true);

            migrationBuilder.AddColumn<bool>(
                name: "IsDisplay",
                table: "SysPermission",
                nullable: false,
                defaultValue: true);

            migrationBuilder.AddColumn<int>(
                name: "Level",
                table: "SysPermission",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.AlterColumn<string>(
                name: "Name",
                table: "SysModule",
                type: "nvarchar(50)",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "nvarchar(10)");

            migrationBuilder.AlterColumn<string>(
                name: "LinkUrl",
                table: "SysModule",
                type: "nchar(1000)",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "nchar(10)");

            migrationBuilder.AlterColumn<string>(
                name: "Area",
                table: "SysModule",
                type: "nvarchar(50)",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nchar(50)",
                oldNullable: true);

            migrationBuilder.AddColumn<string>(
                name: "Group",
                table: "SysModule",
                type: "nvarchar(100)",
                nullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "Parameters",
                table: "AuditLog",
                type: "nvarchar(MAX)",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nvarchar(1500)",
                oldNullable: true);

            migrationBuilder.CreateTable(
                name: "AuditEntry",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime", nullable: false, defaultValueSql: "GETDATE()"),
                    CreateUserId = table.Column<Guid>(nullable: true),
                    ModifiedUserId = table.Column<Guid>(nullable: true),
                    IsDelete = table.Column<bool>(nullable: false, defaultValue: false),
                    ModifiedTime = table.Column<DateTime>(type: "datetime", nullable: true, defaultValueSql: "GETDATE()"),
                    TableName = table.Column<string>(type: "nvarchar(50)", nullable: false),
                    KeyValues = table.Column<string>(type: "nvarchar(500)", nullable: true),
                    OldValues = table.Column<string>(type: "nvarchar(500)", nullable: true),
                    NewValues = table.Column<string>(type: "nvarchar(500)", nullable: true),
                    EntityState = table.Column<int>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AuditEntry", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "SysPermissionModuleMapping",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime", nullable: false, defaultValueSql: "GETDATE()"),
                    CreateUserId = table.Column<Guid>(nullable: true),
                    ModifiedUserId = table.Column<Guid>(nullable: true),
                    IsDelete = table.Column<bool>(nullable: false, defaultValue: false),
                    ModifiedTime = table.Column<DateTime>(type: "datetime", nullable: true, defaultValueSql: "GETDATE()"),
                    PermissionId = table.Column<Guid>(nullable: false),
                    ModuleId = table.Column<Guid>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysPermissionModuleMapping", x => x.Id);
                });
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "AuditEntry");

            migrationBuilder.DropTable(
                name: "SysPermissionModuleMapping");

            migrationBuilder.DropColumn(
                name: "Action",
                table: "SysPermission");

            migrationBuilder.DropColumn(
                name: "IsDisplay",
                table: "SysPermission");

            migrationBuilder.DropColumn(
                name: "Level",
                table: "SysPermission");

            migrationBuilder.DropColumn(
                name: "Group",
                table: "SysModule");

            migrationBuilder.AlterColumn<string>(
                name: "Name",
                table: "SysRole",
                type: "nvarchar(10)",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nvarchar(50)",
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "Code",
                table: "SysRole",
                type: "nvarchar(10)",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nvarchar(50)",
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "Name",
                table: "SysPermission",
                type: "nvarchar(10)",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nvarchar(200)");

            migrationBuilder.AlterColumn<bool>(
                name: "IsEnabled",
                table: "SysPermission",
                nullable: false,
                oldClrType: typeof(bool),
                oldDefaultValue: true);

            migrationBuilder.AlterColumn<string>(
                name: "Icon",
                table: "SysPermission",
                type: "nchar(10)",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nvarchar(100)",
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "Code",
                table: "SysPermission",
                type: "nvarchar(10)",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nvarchar(50)",
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "Name",
                table: "SysModule",
                type: "nvarchar(10)",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "nvarchar(50)");

            migrationBuilder.AlterColumn<string>(
                name: "LinkUrl",
                table: "SysModule",
                type: "nchar(10)",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "nchar(1000)");

            migrationBuilder.AlterColumn<string>(
                name: "Area",
                table: "SysModule",
                type: "nchar(50)",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nvarchar(50)",
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "Parameters",
                table: "AuditLog",
                type: "nvarchar(1500)",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nvarchar(MAX)",
                oldNullable: true);
        }
    }
}
